/*
 * Copyright (C) 2012 Jakub Narloch (jmnarloch@gmail.com), All Rights Reserved.
 */

package org.soa.security.web.controller;

import org.soa.security.model.dto.KeyStoreDTO;
import org.soa.security.model.dto.ServiceConfigurationDTO;
import org.soa.security.service.KeyStoreService;
import org.soa.security.service.SoaServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * <p>Key store controller.</p>
 *
 * <p><strong>Thread safety:</strong> This class is mutable and not thread safe.</p>
 *
 * @author Jakub Narloch (jmnarloch@gmail.com)
 * @version 1.0
 */
@Controller
public class KeyStoreController {

    /**
     * <p>Instance of {@link KeyStoreService} used for operating on key stores.</p>
     *
     * <p>Null by default.</p>
     *
     * <p>Autowired by IOC container.</p>
     */
    @Autowired
    private KeyStoreService keyStoreService;

    /**
     * <p>Creates new instance of {@link KeyStoreController} class.</p>
     */
    public KeyStoreController() {
        // empty constructor
    }

    /**
     * <p>Handles request for all user key stores.</p>
     *
     * @return list of user key stores
     */
    @RequestMapping(value = "/KeyStore/User/{userId}", method = RequestMethod.GET, produces = "application/json")
    @ResponseBody
    public List<KeyStoreDTO> getServicesByUserId(@PathVariable long userId) throws SoaServiceException {

        return keyStoreService.getByUserId(userId);
    }
}
